package org.naxx.security.util;

import java.io.InputStream;

public final class Util {
	
	public static String[] trim(String[] target) {
		for (int i = 0; i < target.length; i++) {
			target[i] = target[i].trim();
		}
		return target;
	}
	
	/**
	 * [(string1)(string2)(string3)] or <code>null</code>
	 */
	public static String format(String[] strings) {
		if(strings == null) {
			return "null";
		}
		StringBuilder buffer = new StringBuilder();
		buffer.append('[');
		for (int i = 0; i < strings.length; i++) {
			buffer.append('(').append(strings[i]).append(")\n");
		}
		buffer.append(']');
		return buffer.toString();
	}
	
	/**
	 * Loads named resource from classpath by using context class
	 * loader of current thread. <br><br>
	 * 
	 * <code>Thread.currentThread().getContextClassLoader()
	 * .getResourceAsStream(classpathResourceName)</code>
	 */
	public static InputStream getFromClasspath(String classpathResourceName) {
		return Thread.currentThread().getContextClassLoader()
			.getResourceAsStream(classpathResourceName);
	}
	
	private Util() {
		throw new IllegalStateException("Can not instantiate class '" 
				+ Util.class.getCanonicalName() + "'");
	}
}
